var ognid = RequestURLParam.getParam("ognid");
var currentTreeNode = null;
var treeObj;
var minForm;

function treeselected(e) {
	var tree = e.sender;
	var node = e.node;
	currentTreeNode = node;
	window.CloseOwnerWindow({
		'id': node.orgId,
		'name': node.orgName
	});

}

function editOrgData() {
	var nodes = treeObj.getCheckedNodes(false);
	window.CloseOwnerWindow(nodes);
}
/***
 * 加载树 
 * */
function initTree() {
	Tree.getTree(treeObj, 'sysOrg!list.do?sysOrg.orgState=1&sysOrg.orgPath=' + ognid, "orgId", "orgPid");
}

$(document).ready(function() {
	treeObj = mini.get("tree");
	initTree();
});

function search() {
	var key = mini.get("key").getValue();
	if(key == "") {
		treeObj.clearFilter();
	} else {
		treeObj.filter(function(node) {
			var text = node.soName ? node.soName.toLowerCase() : "";
			if(text.indexOf(key) != -1) {
				treeObj.selectNode(node);
				var pnode = treeObj.getParentNode(node);
				while(pnode[treeObj.idField]) {
					treeObj.expandNode(pnode);
					pnode = treeObj.getParentNode(pnode);
				}
				return true;
			}
		});
	}
}

function onKeyEnter(e) {
	search();
}